/**
 * 
 */
/**
 * @author Administrator
 *
 */
package cn.edu.tust.controller;
import java.util.List;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.tust.bean.UserInfoBean;
import cn.edu.tust.model.UserInfoModel;
@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet{
	private static final long serialVersion=1L;
	protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
		String strUserName =request.getParameter("userName");
		String strUserPsw =request.getParameter("userPsw");
		System.out.println("username:"+strUserName+";userpsw"+strUserPsw);
		UserInfoBean userInfoB = new UserInfoBean();
		// 存入获取的表单的用户名
		userInfoB.setUserName(strUserName);
		// 存入获取的表单的用户名
		userInfoB.setUserPsw(strUserPsw);
		
		// 调用Model层进行登录信息验证
		UserInfoModel userInfoM = new UserInfoModel();
		// 调用model层的登录验证的业务逻辑处理方法，进行登录验证
		List<UserInfoBean> lstUserInfos = userInfoM.doLogin(userInfoB);
		
		// 验证是否登录成功
		if (lstUserInfos != null && lstUserInfos.size() > 0) {
			// 登录验证成功
			// 跳转到登录成功页面
			// 重定向到登录成功页面
			response.sendRedirect("logined.jsp");
		} else {
			// 登录验证失败
			// 跳转到登录成功页面
			// 重定向到登录成功页面
			response.sendRedirect("index.jsp");
		}
	}

	/**
	 * 用于响应客户端的post请求，将get和post请求进行调用穿接，该类可以处理两种请求
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 调用get请求
		doGet(request, response);
	}

}
